package br.com.salao.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.persistence.Version;

@Entity
@Table(name="agendamento", uniqueConstraints = {@UniqueConstraint(columnNames = { "data", "estabelecimento_id","id_funcionario_servico" })})
public class Agendamento implements Serializable{	
	
	private static final long serialVersionUID = 1L;
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	@Temporal(TemporalType.TIMESTAMP)
	private Date data;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date termino;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "id_funcionario_servico")
	private FuncionarioServicos funcionarioServicos;
	
	private String status;
	@Column(name = "data_cancelado",length=10)
	private Date dataCancelado;
	
	@OneToOne
	@JoinColumn(name = "id_usuario_solicitante")
	private Usuario usuarioSolicitante;
	
	@Temporal(TemporalType.DATE)
	private Date created;
	
	@OneToOne
	private Estabelecimento estabelecimento;
	
	@OneToOne
	private RatingEstabelecimento ratingEstabelecimento;
	
	private int cancelado = 0;
	
	@Transient
	private boolean pendenteRating;
	
	
    @Version
    @Column(name="OPTLOCK")
	private int lock = 1;
	
	public Agendamento(){
		estabelecimento = new Estabelecimento();
		funcionarioServicos = new FuncionarioServicos();
		created = new Date();		
		ratingEstabelecimento = new RatingEstabelecimento();
	}
	
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Date getData() {
		return data;
	}

	public void setData(Date data) {
		this.data = data;
	}


	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public Date getDataCancelado() {
		return dataCancelado;
	}

	public void setDataCancelado(Date dataCancelado) {
		this.dataCancelado = dataCancelado;
	}

	public Usuario getUsuarioSolicitante() {
		return usuarioSolicitante;
	}

	public void setUsuarioSolicitante(Usuario usuarioSolicitante) {
		this.usuarioSolicitante = usuarioSolicitante;
	}

	public FuncionarioServicos getFuncionarioServicos() {
		return funcionarioServicos;
	}

	public void setFuncionarioServicos(FuncionarioServicos funcionarioServicos) {
		this.funcionarioServicos = funcionarioServicos;
	}

	public Date getCreated() {
		return created;
	}	

	public Date getTermino() {
		return termino;
	}

	public void setTermino(Date termino) {
		this.termino = termino;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public Estabelecimento getEstabelecimento() {
		return estabelecimento;
	}

	public void setEstabelecimento(Estabelecimento estabelecimento) {
		this.estabelecimento = estabelecimento;
	}

	public int getCancelado() {
		return cancelado;
	}

	public void setCancelado(int cancelado) {
		this.cancelado = cancelado;
	}

	public int getLock() {
		return lock;
	}

	public void setLock(int lock) {
		this.lock = lock;
	}

	public boolean isPendenteRating() {
		return pendenteRating;
	}

	public void setPendenteRating(boolean pendenteRating) {
		this.pendenteRating = pendenteRating;
	}

	public RatingEstabelecimento getRatingEstabelecimento() {
		return ratingEstabelecimento;
	}

	public void setRatingEstabelecimento(RatingEstabelecimento ratingEstabelecimento) {
		this.ratingEstabelecimento = ratingEstabelecimento;
	}	
}
